package com.gosling.cloudspace.common.constants;

/**
 * 微信状态码
 *
 * @email 1793327033@qq.com
 * @classname WxCodeEnum
 * @author: osc_lihonglin
 */
public enum WxCodeEnum {

    //微信支付状态码
    SUCCESS("SUCCESS", "成功"),
    TRADE_ERROR("TRADE_ERROR", "交易错误"),
    SYSTEMERROR("SYSTEMERROR", "系统错误"),
    SIGN_ERROR("SIGN_ERROR", "签名错误"),
    RULELIMIT("RULELIMIT", "业务规则限制"),
    PARAM_ERROR("PARAM_ERROR", "参数错误"),
    OUT_TRADE_NO_USED("OUT_TRADE_NO_USED", "商户订单号重复"),
    ORDERNOTEXIST("ORDERNOTEXIST", "订单不存在"),
    ORDER_CLOSED("ORDER_CLOSED", "订单已关闭"),
    OPENID_MISMATCH("OPENID_MISMATCH", "openid和appid不匹配"),
    NOAUTH("NOAUTH", "商户无权限"),
    MCH_NOT_EXISTS("MCH_NOT_EXISTS", "商户号不存在"),
    INVALID_TRANSACTIONID("INVALID_TRANSACTIONID", "订单号非法"),
    INVALID_REQUEST("INVALID_REQUEST", "无效请求"),
    FREQUENCY_LIMITED("FREQUENCY_LIMITED", "频率超限"),
    BANKERROR("BANKERROR", "银行系统异常"),
    APPID_MCHID_NOT_MATCH("APPID_MCHID_NOT_MATCH", "appid和mch_id不匹配"),
    ACCOUNTERROR("ACCOUNTERROR", "账号异常");

    String code;
    String errorMessage;

    WxCodeEnum(String code, String errorMessage) {
        this.code = code;
        this.errorMessage = errorMessage;
    }

    /**
     * 根据返回校验码 获取当前异常
     *
     * @param msgCode
     * @return
     */
    public static WxCodeEnum getByCode(String msgCode) {
        for (WxCodeEnum httpCodeEnum : values()) {
            if (httpCodeEnum.code.equals(msgCode)) {
                return httpCodeEnum;
            }
        }
        return SUCCESS;
    }

    public String getCode() {
        return code;
    }

    public String getErrorMessage() {
        return errorMessage;
    }
}
